<?php
class categoryController extends siteController
{
    public function index()
    {
        $cid = intval($_GET['cid']);
        $urlname = in($_GET['urlname']);
        if (empty($cid)&&empty($urlname)) {
            $this->error404();
        }
        if(!empty($cid)){
            $info=model('category_info')->info($cid);
        }else if(!empty($urlname)){
            $info=model('category_info')->info($urlname,true);
        }else{
            $this->error404();
        }
        if (!is_array($info)){
            $this->error404();
        }
        if($info['model']<>APP_NAME){
            $this->error404();
        }
        //位置导航
        $this->nav=api('default','category_nav',$info['cid']);

        if(empty($info['content'])){
            $content='暂无内容';
        }
        $content=html_out($info['content']);

        //读取内容替换
        if(!empty($content)){
            $content=api('default','content_replace',$content);
        }
        //自动增加TAG链接
        if(!empty($content)&&$info['taglink']){
            $content=model('content')->tag_link($content,$info['aid']);
        }

        //内容分页
        $url=url('info/index',array('aid'=>$id,'page'=>'{page}'));
        $page = new Page();
        $content = $page->contentPage(html_out($content), "<hr class=\"ke-pagebreak\" />", $url, 10, 4);
        $info['content']=$content['content'];
        $this->page=$content['page'];
        $this->info=$info;

        //查询上级栏目信息
        $this->parent_category = model('category_info')->info($info['pid']);
        //获取顶级栏目信息
        $this->top_category = model('category_info')->info($this->nav[0]['cid']);

        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>$info['name'],'keywords'=>$info['keywords'],'description'=>$info['description']));
        
        $this->show($info['class_tpl']);
    }

}
